<?php

class ZFEngine_Form_Decorator_CustomContent extends Zend_Form_Decorator_Abstract
{

    const REPLACE = 'REPLACE';

    /**
     *  Render 
     *
     * @param string $content
     * @return string
     */
    public function render($content)
    {
        $customContent = $this->getCustomContent();
        $separator = $this->getSeparator();
        $placement = $this->getPlacement();
        switch ($placement) {
            case self::REPLACE:
                return $customContent;
            case self::PREPEND:
                return $customContent . $separator . $content;
            case self::APPEND:
            default:
                return $content . $separator . $customContent;
        }
    }

    /**
     *
     * @return string
     */
    public function getCustomContent()
    {
        if (null !== ($customContent = $this->getOption('content'))) {
            $this->removeOption('content');
        } else {
            $customContent = '';
        }

        return $customContent;
    }

    
    /**
     * Determine if decorator should append or prepend content
     *
     * @return string
     */
    public function getPlacement()
    {
        $placement = $this->_placement;
        if (null !== ($placementOpt = $this->getOption('placement'))) {
            $placementOpt = strtoupper($placementOpt);
            switch ($placementOpt) {
                case self::APPEND:
                case self::PREPEND:
                case self::REPLACE:
                    $placement = $this->_placement = $placementOpt;
                    break;
                case false:
                    $placement = $this->_placement = null;
                    break;
                default:
                    break;
            }
            $this->removeOption('placement');
        }

        return $placement;
    }

}